package com.singer.software;
import com.singer.domain.Manage;
import com.singer.druid.QuerySinger;
import com.singer.druid.SingerDelete;
import com.singer.piping.CompetitionJdbc;
import com.singer.piping.Delete;
import com.singer.piping.SeringQuery;
import com.singer.druid.Competition;
import com.singer.piping.method.ModifySinger;
import com.singer.piping.method.Increase;
import com.singer.piping.method.Result;

import java.time.LocalDate;
import java.util.Scanner;

public class SingerSoftware {
    Scanner se=new Scanner(System.in);
    LocalDate time= LocalDate.now();
    Manage de=new Manage();

    public void frame() throws Exception {
        while (true) {
            System.out.println("你于"+time+"登录歌手管理系统!");
            System.out.println("=====歌手评分系统=====");
            System.out.println("1->管理员登录。");
            System.out.println("2->管理员注册。");
            System.out.println("3->退出。");
            System.out.println("请选择以下功能（输入1和2选择）:");
            int size=se.nextInt();
            switch(size){
                case 1:
                    frame1();
                case 2:
                   register();
                case 3:
                    break;
            }
        }
    }

    private void frame1()  {
        try {
            while (true) {
                System.out.println("请输入账号:");
                int id = se.nextInt();
                if (de.getId()==id){
                    while (true) {
                        System.out.println("请输入密码:");
                        String password = se.next();
                        if (de.getPassword().equals(password)){
                            System.out.println("登录成功!");
                            ser();
                        }else {
                            System.out.println("密码不对，请重新输入!");
                        }
                    }
                }else {
                    System.out.println("id错误请重新输入!");
                }
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }


    private void register() throws Exception {
        System.out.println("===注册系统界面===");
        System.out.println("请输入你的账户id:");
        int id = se.nextInt();
        de.setId(id);
        System.out.println("请输入密码:");
        String password1 = se.next();
        de.setPassword(password1);
        System.out.println("恭喜你注册管理员成功id为:"+id+"  "+"密码为:"+password1);
        frame();
    }

    public void ser() throws Exception {
        System.out.println("====操作系统====");
        System.out.println("1->增添!");
        System.out.println("2->删除!");
        System.out.println("3->查询!");
        System.out.println("4->修改!");
        System.out.println("5->比赛!");
        System.out.println("6->排名查询!");
        System.out.println("请选择以下功能（输入数字选择）:");
        int a=se.nextInt();
        switch (a){
            case 1:
                increase();
            case 2:
                delete();
            case 3:
                query();
            case 4:
                modify();
            case 5:
              competition();
            case 6:
                result();
        }
    }

    private void increase() throws Exception{
        Increase se=new Increase();
        se.add1();
        ser();
    }
    private void query() throws Exception {
        SeringQuery er=new QuerySinger();
        System.out.println("===查询界面===");
        System.out.println("1->歌手查询");
        System.out.println("2->裁判查询");
        int w=se.nextInt();
         if (w==1){
             er.query1();
         }else {
             er.query2();
         }
             ser();
    }

    private void modify() throws Exception {
        ModifySinger sr=new ModifySinger();
        sr.del();
        ser();
    }
    private void delete() throws Exception {
        Delete delete=new SingerDelete();
        System.out.println("===删除界面===");
        System.out.println("1->删除歌手");
        System.out.println("2->删除裁判");
        int w=se.nextInt();
        if (w==1){
            System.out.println("请输入要删除歌手的id:");
            int Id1= se.nextInt();
            delete.delete(Id1);
        }else {
            System.out.println("请输入要删除歌手的id:");
            int Id2= se.nextInt();
            delete.delete1(Id2);
        }
         ser();
    }
    private void competition() throws Exception {
        CompetitionJdbc de=new Competition();
        de.competition();
    }
    private void result() throws Exception {
        Result res=new Result();
        res.pro();
        ser();
    }
}
